package mxmf.content;

import java.util.List;

import mxmf.content.meta.ContentMetaContext;
import mxmf.entity.content.Content;

public class ExecuteHandler {

    public void execute(ContentHandler<Content> handler, ActionEnum actionEnum,
            ContentMetaContext meta, Content content) {
        if (handler == null) {
            return;
        }
        switch (actionEnum) {
        case CREATE:
            handler.afterCreate(content, meta);
            break;
        case UPDATE:
            handler.afterUpdate(content, meta);
            break;
        case DELETE:
            handler.afterDelete(content, meta);
            break;
        case ONLINE:
            handler.afterOnline(content, meta);
            break;
        case OFFLINE:
            handler.afterOffline(content, meta);
            break;
        case DISABLE:
            handler.afterDisable(content, meta);
            break;
        case ENABLE:
            handler.afterEnable(content, meta);
            break;
        default:
            break;
        }

    }

    public void execute(List<ContentHandler<Content>> contentHandlers, ActionEnum actionEnum,
            Content content, ContentMetaContext meta) {

        if (contentHandlers != null) {
            contentHandlers.forEach(h -> execute(h, actionEnum, meta, content));
        }

        execute(meta.getContentHandler(), actionEnum, meta, content);

    }

    public void execute(ActionEnum actionEnum, Content content) {
        execute(null, actionEnum, null, content);

    }
}
